<?php
namespace Game\Action;

abstract class AbstractAction
{
    /**
     *
     * @var Object
     */
    protected $_owner;

    /**
     * Code for identify action
     * @var string
     */
    protected $_code;

    /**
     *
     * @var string
     */
    protected $_message;

    /**
     * Returns description of action
     *
     * @return string
     */
    abstract public function getCode();

    /**
     * Returns description of action
     *
     * @return string
     */
    abstract public function getDescription();

    /**
     * Apply action to object
     * @param Object $object
     * @return string Action's result message
     */
    abstract public function execute($object);

    /**
     * Returns array with info about action
     * @return array
     */
    abstract public function getResultArray();

    /**
     *
     * @param Object $owner
     */
    public function setOwner($owner)
    {
        $this->_owner = $owner;
    }

    /**
     *
     * @return Object
     */
    public function getOwner()
    {
        return $this->_owner;
    }

    public function getMessage()
    {
        return $this->_message;
    }

    /**
     * Renders the result of the action
     *
     * @return string
     */
    public function render()
    {
        return json_encode($this->getResultArray());
    }

    public function __toString()
    {
        return $this->render();
    }
}